Miller-Rabin randomized primality test (1976, 1980)
There is a randomized algorithm running in time that, with probability determines if an -bit integer is prime.
MillerRabin(n)
If and is even, return composite.
/* Factor as where is odd. */
while is even
end /* Done. . */
Choose uniformly at random.
Compute each of the numbers .
If , return composite.
for
If and , return composite.
end /* Done checking for fake square roots. */
Return probably prime.
See also: PRIMES is in P paper
References:
- G. L. Miller, “Riemann’s hypothesis and tests for primality,” Proceedings of seventh annual ACM symposium on Theory of computing - STOC ’75, pp. 234–239, May 1975. doi: 10.1145/800116.803773
- M. O. Rabin, “Probabilistic algorithm for testing primality,” Journal of Number Theory, vol. 12, no. 1, pp. 128–138, 1980. doi: 10.1016/0022-314x(80)90084-0
- https://en.wikipedia.org/wiki/Miller–Rabin_primality_test
- https://www.cs.cornell.edu/courses/cs4820/2010sp/handouts/MillerRabin.pdf